package gui;

import java.awt.*;
import javax.swing.*;

import physics.Location;
import physics.Vector;

import fiziksobject.FiziksBall;

import java.awt.event.*;

public class FiziksBallProperties extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private FiziksBallProperties thiz = this;
	private NumberInput mass;
	private NumberInput radius;
	private NumberInput charge;
	private VectorModifier velocity;
	private Location loc;
	private final FiziksBall fb;
	private ColorButton color;
	public FiziksBallProperties(final FiziksBall fb) {
		setLayout(new BoxLayout(getContentPane(),BoxLayout.Y_AXIS));
		this.fb = fb;
		mass = new NumberInput("Mass (kg)",fb.getMass());
		radius = new NumberInput("Radius (m)",fb.getRadius());
		charge = new NumberInput("Charge (C)",fb.getCharge());
		velocity = new VectorModifier(fb.getMomentum().divide(fb.getMass()));
		color = new ColorButton("Color",fb.getColor());
		add(mass);
		add(radius);
		add(charge);
		add(velocity);
		add(color);
		
		JButton ok = new JButton("Ok");
		ok.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				fb.setMass(mass.getNum());
				fb.setRadius(radius.getNum());
				fb.setCharge(charge.getNum());
				fb.setMomentum(velocity.getVector().multiply(fb.getMass()));
				fb.setColor(color.getColor());
				WindowEvent wev = new WindowEvent(thiz, WindowEvent.WINDOW_CLOSING);
                Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
			}
		});
		add(ok);
	}
}
